//package com.questionnaire.core.bridge.impl;
//
//
//import com.questionnaire.common.base.ShiroUser;
//import com.questionnaire.constant.CacheConstant;
//import com.questionnaire.core.SimpleCacheService;
//import com.questionnaire.core.adapter.UserAdapter;
//import com.questionnaire.core.bridge.UserBridgeService;
//import com.questionnaire.core.shiro.Cache.SimpleMapCache;
//import com.questionnaire.modular.system.model.Role;
//import com.questionnaire.utils.EmptyUtil;
//import com.questionnaire.utils.ShiroKit;
//import org.apache.shiro.authz.AuthorizationInfo;
//import org.apache.shiro.authz.SimpleAuthorizationInfo;
//import org.apache.shiro.cache.Cache;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
///**
// * @Description：用户信息桥接（后期会做缓存）
// */
//@Component("userBridgeService")
//public class UserBridgeServiceImpl implements UserBridgeService {
//
//
//    @Autowired
//    SimpleCacheService simpleCacheService;
//    @Autowired
//    UserAdapter userAdapter;
//
//    @Override
//    public List<String> findRoleList(String key, String userId) {
//        List<Role> roles = new ArrayList<>();
//        //获得缓存
//        Cache<Object, Object> cache = simpleCacheService.getCache(key);
//        //缓存存在
//        if (!EmptyUtil.isNullOrEmpty(cache)){
//            roles = (List<Role>) cache.get(key);
//        }else {
//            //缓存不存在
//            roles = userAdapter.findRoleByUserId(userId);
//            if (!EmptyUtil.isNullOrEmpty(roles)){
//                Map<Object,Object> map = new HashMap<>();
//                map.put(key, roles);
//                SimpleMapCache simpleMapCache = new SimpleMapCache(key, map);
//                simpleCacheService.creatCache(key,simpleMapCache );
//            }
//        }
//
//        List<String> roleLabel = new ArrayList<>();
//        for (Role role : roles) {
//            roleLabel.add(role.getLabel());
//        }
//        return roleLabel;
//    }
//
//    @Override
//    public List<String> findResourcesList(String key, String userId) {
//        return null;
//    }
//
//    @Override
//    public void loadUserAuthorityToCache(ShiroUser shiroUser) {
//        String sessionId = (String) ShiroKit.getSession().getId();
//        String roleKey = CacheConstant.ROLE_KEY+sessionId;
//        String resourcesKey = CacheConstant.RESOURCES_KEY+sessionId;
//        //查询用户对应的角色标识
//        List<String> roleList = this.findRoleList(roleKey,shiroUser.getId());
//        //查询用户对于的资源标识
//        List<String> resourcesList = this.findResourcesList(resourcesKey,shiroUser.getId());
//    }
//}
